using System.Collections.Generic;
using System.IO;
using UnityEditor;
using UnityEngine;
namespace Framework.Core.Editor
{


    public class FrameworkHelper
    {
        [MenuItem("Framework/Set Excel Folder", false, 104)]
        public static void SetExcelFolder()
        {
            string lastExcelPath = EditorPrefs.GetString("ExcelPath", default);
            string tempExcelPath = EditorUtility.OpenFolderPanel("Set Excel store folder", lastExcelPath ?? Application.dataPath, "");
            if (!tempExcelPath.IsNullOrEmpty())
            {
                EditorPrefs.SetString("ExcelPath", tempExcelPath);
            }
            Debug.Log("Set Excel store folder：" + tempExcelPath);
        }

        [MenuItem("Framework/Excel export", false, 205)]
        public static void LoadAllExcelData()
        {
            ExcelDataTool.LoadAllExcelData();
        }


        [MenuItem("Framework/Editor Mode（勾选）")]
        public static void SwitchIsEditorMode()
        {
            bool isEditorMode = EditorPrefs.GetBool("IsEditorMode", false);
            EditorPrefs.SetBool("IsEditorMode", !isEditorMode);
        }

        [MenuItem("Framework/Reload Excel Runtime", false, 101)]
        public static void ReLoadExcelData()
        {
            ReadExcel.Instance.LoadAllExcelData();
        }

        // 加载时初始化方法，统一管理调用顺序
        [InitializeOnLoadMethod]
        private static void InitializeOnLoadMethods()
        {
            // 注册编辑器退出事件
            EditorApplication.quitting += OnEditorQuit;
        }

        private static void OnEditorQuit()
        {
            EditorPrefs.SetBool("compilationFinished", false);
            EditorPrefs.SetBool("compilationFinishedBuildAB", false);
            EditorPrefs.SetBool("compilationFinishedBuildPkg", false);
        }

    }
}
